package com.czxy.service.impl;

import com.czxy.dao.RoseDao;
import com.czxy.dao.StaffDao;
import com.czxy.domain.Rose;
import com.czxy.domain.Staff;
import com.czxy.domain.StaffVo;
import com.czxy.service.StaffService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhangmengxiang1@itcast.cn
 * @version 1.0
 * @date 2020/2/3
 */
@Service
public class StaffServiceimpl implements StaffService {
    @Resource
    private StaffDao staffDao;
    @Resource
    private RoseDao roseDao;


    @Override
    public PageInfo<Staff> findAllStaffForpage(StaffVo staffVo) {
        PageHelper.startPage(staffVo.getPageNum(),staffVo.getPageSize());
        List<Staff> staffList = staffDao.findAllStaffForpage(staffVo);
        return new PageInfo<>(staffList);
    }

    @Override
    public void addStaff(Staff staff) {
        staff.setState(1);
        staffDao.insert(staff);
    }

    @Override
    public void delStaffByHid(Integer hid) {
        staffDao.deleteByPrimaryKey(hid);
    }

    @Override
    public void delAllStaffByDir(String dir) {
        String[] split = dir.split(",");
        for (String s : split) {
            staffDao.deleteByPrimaryKey(Integer.parseInt(s));
        }
    }

    @Override
    public Staff findOneStaffByhid(Integer hid) {
        Staff staff = staffDao.findOneStaffByhid(hid);
        return staff;
    }

    @Override
    public void updateStaff(Staff staff) {
        staffDao.updateByPrimaryKeySelective(staff);
    }

    @Override
    public List<Rose> findAllRose() {
        return roseDao.selectAll();
    }

    @Override
    public Staff login(Staff staff) {
        Staff staff1 = staffDao.login(staff);
        return staff1;
    }
}
